home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABOtherTopic.c
-
- NAME
- ABOtherTopic.c, part of the ABox project source code,
- responsible for handling the ABOtherTopic class stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 13 july 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 28-july-94 - ty - 1.0.6 -- removed cursor flipping from Load
- 10-apr-95 - ty - added support for TeachText/SimpleText 'ttro'
- documents (but only as text, no pict processing)
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABOtherTopic.h"
- #include "ABoxDefs.h"
-
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
-
- /*=============================== ABOtherTopic::ABOtherTopic ================================*/
- ABOtherTopic::ABOtherTopic(const FSSpec& inTopicFSSpec)
- : ABTopic(inTopicFSSpec)
- {
- this->ResetSlideInfo();
-
- this->BlurbRef() = NULL;
- this->FileTypeRef() = kABbadFileType;
- this->TopicType() = ETopicType_OtherTopic;
- } // end ABOtherTopic
-
-
-
-
- /*=============================== ABOtherTopic::~ABOtherTopic ================================*/
- ABOtherTopic::~ABOtherTopic(void)
- {
- if (this->HasBlurb())
- {
- delete this->BlurbRef();
- this->BlurbRef() = NULL;
- }
-
- } // end ~ABOtherTopic
-
-
-
-
- /*=============================== ABOtherTopic::GetProperty ================================*/
- OSErr ABOtherTopic::GetProperty(ABProperty prop,
- void *ptr,
- long *ptrSize)
- {
- OSErr error = noErr;
- long pSize;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABTopicIsFolder:
- *((Boolean *)ptr) = (this->FileTypeRef() == kABFolderFileType);
- pSize = kABTopicIsFolderSize;
- break;
- case kABTopicFileType:
- *((ABTopicFileType *)ptr) = this->FileTypeRef();
- pSize = kABTopicFileTypeSize;
- break;
- default:
- error = kABOtherTopicSuperProperties::GetProperty(prop, ptr, ptrSize);
- break;
- } // end switch block
-
- if (ptrSize && !error)
- *ptrSize = pSize;
- return error;
-
- } // end GetProperty
-
-
-
-
-
- /*=============================== ABOtherTopic::SetProperty ================================*/
- OSErr ABOtherTopic::SetProperty(ABProperty prop,
- void *ptr,
- long ptrSize)
- {
- OSErr error = noErr;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABTopicIsFolder:
- error = kABPropertyReadOnly;
- break;
-
- default:
- error = kABOtherTopicSuperProperties::SetProperty(prop, ptr, ptrSize);
- break;
- } // end switch block
-
- return error;
-
- } // end SetProperty
-
-
-
-
-
-
-
- /*=============================== ABOtherTopic::Resize ===============================*/
- //
- // this function will rearrange and resize the picture and the
- // text fields that appear on a slide.
- //
- // This method will cause the current slide for the
- // topic to resize by invoking that item's resize method.
- //
- // is called by:
- //
- OSErr ABOtherTopic::Resize (Rect const *field)
- {
- OSErr error = noErr;
- Rect box;
-
- // begin here...
-
- error = ABTopic::Resize(field);
- if (error == noErr)
- {
- box = *field;
- if (this->HasBlurb())
- error = this->BlurbRef()->SetProperty(kABObjectRect, &box, kABObjectRectSize);
- else
- error = paramErr;
- } // endif else block
-
- return error;
- } // end of Resize
-
-
-
-
-
- /*=============================== ABOtherTopic::OpenTopic ================================*/
- OSErr ABOtherTopic::OpenTopic(void)
- {
- OSErr error = noErr;
-
- Handle dataHandle = NULL;
- short blurbResID;
- short tempRefNum;
- long dataCount;
- const long headerOffset = 512;
- const long thirtyTwoKLimit = 32767;
-
- // begin here...
-
- // now load the data and create a "resource" outta it...
- //
- ABUCursor::WatchCursor();
- if (this->HasBlurb())
- {
- delete this->BlurbRef();
- this->BlurbRef() = NULL;
- }
-
- // now...if the "fileType" is something like kABfolderFileType
- // then we're dealing with a folder, and we should just display
- // the standard folder message (which comes from a resource).
- // If, however, the fileType is something else we'd be interested
- // in, then we need to create some storage.
- if (this->DoesntHaveFSSpecPointer() && this->IsNotFolder())
- {
- ABUCursor::ArrowCursor();
- return resNotFound;
- }
-
- switch (this->GetFileType())
- {
- case kABFolderFileType:
- // yup, it's a folder, so set resourceID to use
- //
- // switch to the ABox resource file first...
- (void)this->UseTopicResFile();
-
- blurbResID = kABfolderTextSlide;
- this->BlurbRef() = new ABText;
- break;
- case kABbadFileType:
- // huh? this shouldn't happen...
- ABUCursor::ArrowCursor();
- return resNotFound;
- break;
- case kABPictResource:
- case kABTextResource:
- case kABTeachTextReadOnly:
- // something else, so we need to create some storage
-
- // open the file...
- error = ::FSpOpenDF (this->FSSpecPointerRef(), fsRdPerm, &tempRefNum);
- if (error)
- return error;
-
- // find out how large
- error = ::GetEOF(tempRefNum, &dataCount);
- if (error)
- {
- ::FSClose (tempRefNum);
- ABUCursor::ArrowCursor();
- return error;
- } // end if
-
- // create some storage...
- dataHandle = ::NewHandle (dataCount);
- error = ::MemError();
- if (error)
- {
- ::FSClose (tempRefNum);
- ABUCursor::ArrowCursor();
- return error;
- } // end if
-
- // read the file's data into memory
-
- switch (this->GetFileType())
- {
- case kABFolderFileType:
- // this shouldn't get here...then again
- error = resNotFound;
- break;
- case kABPictResource:
- // read a PICT file:
- // advance past the 512 byte header of a PICT file
- //
- this->BlurbRef() = new ABPict;
- error = ::SetFPos ( tempRefNum, fsFromStart, headerOffset );
- dataCount -= headerOffset;
- ::SetHandleSize (dataHandle, dataCount);
- break;
- case kABTeachTextReadOnly:
- // added support for the 'ttro' teach-/simple-text read
- // only text document. We must do this because the file
- // type gets mapped to a resource type
- this->FileTypeRef() = kABTextResource;
-
- // fall-thru is intentional!
-
- case kABTextResource:
- // limit the stuff read to 32K!
- this->BlurbRef() = new ABText;
- if (dataCount > thirtyTwoKLimit)
- {
- dataCount = thirtyTwoKLimit;
- ::SetHandleSize (dataHandle, dataCount);
- } // end if block
-
- break;
- default:
- // huh?
- error = resNotFound;
- break;
- } // end switch block
-
- if (error || this->DoesntHaveBlurb())
- {
- if (!error && this->DoesntHaveBlurb())
- error = ::MemError();
- ::FSClose (tempRefNum);
- ::DisposHandle(dataHandle);
- ABUCursor::ArrowCursor();
- return error;
- } // end if
-
- // now read the data into the handle and close up the file
- ::HLock(dataHandle);
- error = ::FSRead ( tempRefNum, &dataCount, *dataHandle);
- ::HUnlock (dataHandle);
- (void)::FSClose (tempRefNum);
- if (error)
- {
- ::DisposHandle(dataHandle);
- ABUCursor::ArrowCursor();
- return error;
- } // end if
-
- // synthesize the resource so the ABResource object can use it properly
- // <pretty sneaky, eh?>
- //
- // switch to the resource file (hopefully, the application one)
- if (this->DoesntHaveFileRefNum())
- ::UseResFile(this->GetFileRefNum());
-
- blurbResID = ::UniqueID(this->GetFileType());
- ::AddResource (dataHandle,
- this->GetFileType(),
- blurbResID,
- kABSyntheticResourceName);
- error = ::ResError();
- if (error)
- {
- ABUCursor::ArrowCursor();
- return error;
- } // end if block
-
- // now shove the resource into the ABResource object
- error = this->BlurbRef()->SetProperty (kABResourceHandle, &dataHandle, kABResourceHandleSize);
- break;
- default:
- // huh? we should never get here...
- error = resNotFound;
- break;
- } // end switch block
-
- if (error == noErr)
- if (this->HasBlurb())
- // set the resource ID for the ABResource object
- error = this->BlurbRef()->SetProperty (kABResourceResID, &blurbResID, kABResourceResIDSize);
- else
- error = ::MemError();
-
-
- ABUCursor::ArrowCursor();
-
- return error;
- } // end OpenTopic
-
-
-
-
-
- /*=============================== ABOtherTopic::CloseTopic ================================*/
- OSErr ABOtherTopic::CloseTopic(void)
- {
- OSErr error = noErr;
- Handle resHandle;
- short resAttributes;
-
- // begin here...
- ABUCursor::WatchCursor();
-
- if (this->HasBlurb())
- error = this->BlurbRef()->GetProperty (kABResourceHandle, &resHandle, NULL);
-
- if ((error == noErr) && resHandle && this->HasBlurb())
- {
- if (this->IsNotFolder())
- {
- short oldResFile = this->UseTopicResFile();
-
- resAttributes = ::GetResAttrs(resHandle);
- ::RmveResource (resHandle);
- error = ::ResError();
- if (resAttributes & resChanged)
- {
- resAttributes ^= resChanged;
- ::SetResAttrs (resHandle, resAttributes);
- error = ::ResError();
- } // end if block
-
- ::RmveResource (resHandle);
- ::UpdateResFile (this->GetFileRefNum());
- error = ::ResError();
- ::DisposHandle ((Handle)resHandle);
- resHandle = NULL;
- error = this->BlurbRef()->SetProperty (kABResourceHandle, &resHandle, kABResourceHandleSize);
-
- ::UseResFile(oldResFile);
-
- } // end if block
-
- delete this->BlurbRef();
- this->BlurbRef() = NULL;
- } // end if block
-
- ABUCursor::ArrowCursor();
- return error;
- } // end CloseTopic
-
-
-
-
-
- /*=============================== ABOtherTopic::DoLoad ===============================*/
- //
- OSErr ABOtherTopic::DoLoad (void)
- {
- return noErr;
-
- } // end of function DoLoad
-
-
-
-
-
- /*=============================== ABOtherTopic::DoCheckSlides ===============================*/
- //
- // This function checks a file's type and will return a zero value
- // if it is not acceptable, or a non-zero valuee(1) to indicate
- // that it is acceptable.
- //
- // is called by:
- //
- short ABOtherTopic::DoCheckSlides (void)
- {
- const short badCount = 0;
- short count = badCount;
- FInfo fileInfo;
- OSErr error = noErr;
-
- const Boolean resolvedAliasChains = true;
- Boolean targetIsFolder = false;
- Boolean wasAliased = false;
-
- // begin here...
-
-
- if (this->DoesntHaveFSSpecPointer())
- return badCount;
-
- // i can't assume that the alias has been resolved, nor do
- // i want to at this point. What i'm really concerned with is
- // whether the FSSpecPtr describes a file (which will be useful),
- // or a folder (which will also be useful). Since FSpGetFInfo()
- // can't tell me if the file is/isn't a folder, i'll use
- // ResolveAliasFile and only pay attention to the targetIsFolder
- // return value.
-
- error = ::ResolveAliasFile (this->FSSpecPointerRef(),
- resolvedAliasChains,
- &targetIsFolder,
- &wasAliased);
- if (error)
- return badCount;
-
- if (targetIsFolder)
- {
- // so, the FSSpecPtr described a folder
- this->FileTypeRef() = kABFolderFileType;
- //this->FileRefNumRef() = ::CurResFile();
- count = 1;
- } else {
- // well, the FSSpecPtr described a file, but
- // what kind? Let's try to find out initially
- // by examining the fileType code that the system
- // returns to us
- //
-
- error = ::FSpGetFInfo (this->FSSpecPointerRef(), &fileInfo);
- if (error == noErr)
- {
- // check the file's type and decide then and there...save the
- // filetype into our member field "fileType" if it is acceptable
- switch (fileInfo.fdType)
- {
- case kABPictResource:
- case kABTextResource:
- case kABTeachTextReadOnly:
- // this is a good topic!
- this->FileTypeRef() = fileInfo.fdType;
- count = 1;
- break;
- default:
- // well...it _could_ be a movie, but let someone
- // else figure that one out! (Actually, that will
- // be taken care of by our caller, so don't worry!)
- break;
- } // end switch block
- }
-
- } // end if block
-
- return count;
- } // end of function DoCheckSlides
-
-
-
-
- /*=============================== ABOtherTopic::Draw ================================*/
- OSErr ABOtherTopic::Draw(WindowPtr window)
- {
- OSErr error = noErr;
-
- // begin here...
- //
- short oldResFile = this->UseTopicResFile();
-
- if (this->HasBlurb())
- {
- error = ABObject::Draw(window);
- if (!error)
- error = this->BlurbRef()->Draw(window);
-
- } // end if else block
-
- ::UseResFile (oldResFile);
-
- return error;
-
- } // end Draw
-
-
-
-
-
- /*=============================== ABOtherTopic::Update ================================*/
- OSErr ABOtherTopic::Update(WindowPtr window)
- {
- OSErr error = noErr;
-
- short oldResFile = this->UseTopicResFile();
-
- // begin here...
- //
- if (this->HasBlurb())
- {
- error = this->BlurbRef()->Update(window);
- } else {
- error = noErr;
- } // end if else block
-
- ::UseResFile (oldResFile);
-
- return error;
- } // end Update
-
-
-
-
- /*=============================== ABOtherTopic::Event ================================*/
- Boolean ABOtherTopic::Event(EventRecord *eventRec)
- {
- Boolean test = false;
-
- // begin here...
- //
- short oldResFile = this->UseTopicResFile();
-
- if (this->HasBlurb())
- test = this->BlurbRef()->Event(eventRec);
-
- ::UseResFile (oldResFile);
-
- return test;
- } // end Event
-
-
-
-
-
- /*=============================== ABOtherTopic::Stop ================================*/
- OSErr ABOtherTopic::Stop(void)
- {
- OSErr error = noErr;
-
- short oldResFile = this->UseTopicResFile();
-
- error = this->CloseTopic();
-
- ::UseResFile (oldResFile);
-
- return error;
-
- } // end Stop
-
-
-
-
-
-
- // end of file
-
-